<template>
<div class="wrap" @keyup.enter="login">
  <div class="container">
    <h1>泰国游戏</h1>
    <form class="login_form">
      <el-input v-model="user.account" id="account" size="mini" placeholder="userName"></el-input>
      <el-input v-model="user.password" type="password" id="password" size="mini" placeholder="password"></el-input>
      <center><el-button round style="background: transparent; color:gray" @click="login">Login</el-button></center>
    </form>
  </div>
  <ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
  </ul>
</div>
</template>
<style>
#account, #password {
  margin-bottom: 8px;
}
</style>

<style scoped>
        * {
            box-sizing: border-box;
        }
        body {
            margin: 0;
            padding: 0;
            font: 16px/20px microsft yahei;
            height: 100%;
        }
        .wrap {
            width: 100%;
            height: 100%;
            padding: 40px 0;
            position: fixed;
            opacity: 0.8;
            background: linear-gradient(to bottom right,#50a3a2,#53e3a6);
            background: -webkit-linear-gradient(to bottom right,#50a3a2,#53e3a6);
        }
        .container {
            width: 60%;
            margin: 0 auto;
        }
        .container h1 {
            text-align: center;
            color: #FFFFFF;
            font-weight: 500;
        }
        .container input {
            width: 70;
            display: block;
            height: 36px;
            border: 0;
            outline: 0;
            padding: 6px 10px;
            line-height: 24px;
            margin: 32px auto;
            -webkit-transition: all 0s ease-in 0.1ms;
            -moz-transition: all 0s ease-in 0.1ms;
            transition: all 0s ease-in 0.1ms;
        }
        .container input[type="text"] , .container input[type="password"]  {
            background-color: #FFFFFF;
            font-size: 16px;
            color: #50a3a2;
        }
        .container input[type='submit'] {
            font-size: 16px;
            letter-spacing: 2px;
            color: #666666;
            background-color: #FFFFFF;
        }
        .container input:focus {
            width: 400px;
        }
        .container input[type='submit']:hover {
            cursor: pointer;
            width: 100px;
        }

        .wrap ul {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -10;
        }
        .wrap ul li {
            list-style-type: none;
            display: block;
            position: absolute;
            bottom: -120px;
            width: 15px;
            height: 15px;
            z-index: -8;
            background-color:rgba(255, 255, 255, 0.15);
            animotion: square 25s infinite;
            -webkit-animation: square 25s infinite;
        }
        .wrap ul li:nth-child(1) {
            left: 0;
            animation-duration: 10s;
            -moz-animation-duration: 10s;
            -o-animation-duration: 10s;
            -webkit-animation-duration: 10s;
        }
        .wrap ul li:nth-child(2) {
            width: 40px;
            height: 40px;
            left: 10%;
            animation-duration: 15s;
            -moz-animation-duration: 15s;
            -o-animation-duration: 15s;
            -webkit-animation-duration: 15s;
        }
        .wrap ul li:nth-child(3) {
            left: 20%;
            width: 25px;
            height: 25px;
            animation-duration: 12s;
            -moz-animation-duration: 12s;
            -o-animation-duration: 12s;
            -webkit-animation-duration: 12s;
        }
        .wrap ul li:nth-child(4) {
            width: 50px;
            height: 50px;
            left: 30%;
            -webkit-animation-delay: 3s;
            -moz-animation-delay: 3s;
            -o-animation-delay: 3s;
            animation-delay: 3s;
            animation-duration: 12s;
            -moz-animation-duration: 12s;
            -o-animation-duration: 12s;
            -webkit-animation-duration: 12s;
        }
        .wrap ul li:nth-child(5) {
            width: 60px;
            height: 60px;
            left: 40%;
            animation-duration: 10s;
            -moz-animation-duration: 10s;
            -o-animation-duration: 10s;
            -webkit-animation-duration: 10s;
        }
        .wrap ul li:nth-child(6) {
            width: 75px;
            height: 75px;
            left: 50%;
            -webkit-animation-delay: 7s;
            -moz-animation-delay: 7s;
            -o-animation-delay: 7s;
            animation-delay: 7s;
        }
        .wrap ul li:nth-child(7) {
            left: 60%;
            animation-duration: 8s;
            -moz-animation-duration: 8s;
            -o-animation-duration: 8s;
            -webkit-animation-duration: 8s;
        }
        .wrap ul li:nth-child(8) {
            width: 90px;
            height: 90px;
            left: 70%;
            -webkit-animation-delay: 4s;
            -moz-animation-delay: 4s;
            -o-animation-delay: 4s;
            animation-delay: 4s;
        }
        .wrap ul li:nth-child(9) {
            width: 100px;
            height: 100px;
            left: 80%;
            animation-duration: 20s;
            -moz-animation-duration: 20s;
            -o-animation-duration: 20s;
            -webkit-animation-duration: 20s;
        }
        .wrap ul li:nth-child(10) {
            width: 120px;
            height: 120px;
            left: 90%;
            -webkit-animation-delay: 6s;
            -moz-animation-delay: 6s;
            -o-animation-delay: 6s;
            animation-delay: 6s;
            animation-duration: 30s;
            -moz-animation-duration: 30s;
            -o-animation-duration: 30s;
            -webkit-animation-duration: 30s;
        }

        @keyframes square {
            0%  {
                    -webkit-transform: translateY(0);
                    transform: translateY(0)
                }
            100% {
                    bottom: 400px;
                    transform: rotate(600deg);
                    -webit-transform: rotate(600deg);
                    -webkit-transform: translateY(-500);
                    transform: translateY(-500)
            }
        }
        @-webkit-keyframes square {
            0%  {
                -webkit-transform: translateY(0);
                transform: translateY(0)
            }
            100% {
                bottom: 400px;
                transform: rotate(600deg);
                -webit-transform: rotate(600deg);
                -webkit-transform: translateY(-500);
                transform: translateY(-500)
            }
        }
    </style>

<script>
import md5 from 'js-md5'
export default {
  watch: {
    $route () {
      window.location.reload()
    }
  },
  data () {
    return {
      user: {
        account: '',
        password: ''
      }
    }
  },
  methods: {
    login () {
      let that = this

      if (!this.checkPassWord(this.user.account) || !this.checkPassWord(this.user.password)) {
        this.$message.error('账号密码为8-16位数字字母组合')
        return false
      }

      this.$axios({
        method: 'get',
        url: '/api/AuthService.login',
        params: {'account': this.user.account, 'password': md5(this.user.password)},
        async: false
      })
      .then(function (resp) {
        if (resp.data.status === 'success') {
          sessionStorage.setItem('account', resp.data.account)
          sessionStorage.setItem('role', resp.data.role)
          sessionStorage.setItem('menu', JSON.stringify(resp.data.menu))
          that.$router.push({name: 'Home'})
        } else {
          that.$message({
            showClose: true,
            message: resp.data.cause,
            type: 'warning'
          })
          return false
        }
      })
    },
    tockenLogin (tocken) {
      let that = this

      this.$axios({
        method: 'get',
        url: '/api/AuthService.gameLogin',
        params: {'token': tocken},
        async: false
      })
      .then(function (resp) {
        if (resp.data.status === 'success') {
          sessionStorage.setItem('account', resp.data.account)
          sessionStorage.setItem('role', resp.data.role)
          sessionStorage.setItem('menu', JSON.stringify(resp.data.menu))
          that.$router.push({name: 'Home'})
        } else {
          that.$message({
            showClose: true,
            message: resp.data.cause,
            type: 'warning'
          })
          return false
        }
      })
    },
    isLogin () {
      let that = this

      this.$axios({
        method: 'get',
        url: '/api/AuthService.isLogin',
        async: false
      })
      .then(function (resp) {
        if (resp.data.status === 'success') {
          sessionStorage.setItem('account', resp.data.account)
          sessionStorage.setItem('role', resp.data.role)
          sessionStorage.setItem('menu', JSON.stringify(resp.data.menu))
          that.$router.push({name: 'Home'})
        } else {
        }
      })
    },
    autoLogin () {
      let that = this
      this.$axios({
        method: 'get',
        url: '/api/AuthService.quit'
      })
      .then(function (resp) {
        if (resp.data.status === 'success') {
          that.login()
        }
      })
    },
    checkPassWord (str) {
      if (str === null || str.length < 4 || str.length > 16) {
        return false
      } else {
        return true
      }
    }
  },
  mounted () {
    if (this.$route.params.account !== undefined && this.$route.params.password !== undefined && this.$route.params.auto === 1) {
      this.user.account = this.$route.params.account
      this.user.password = this.$route.params.password
      this.autoLogin()
      return false
    }

    // tip 1:登录过期
    if (this.$route.query.tip !== undefined) {
      if (this.$route.query.tip === '1') {
        this.$message({
          showClose: true,
          message: '登陆已过期请重新登陆',
          type: 'success'
        })
        return false
      }
      if (this.$route.query.tip === '2') {
        this.$message({
          showClose: true,
          message: '维护已开启请稍后尝试登陆',
          type: 'success'
        })
        return false
      }
      if (this.$route.query.tip === '3') {
        this.$message({
          showClose: true,
          message: '你的账号已被冻结',
          type: 'error'
        })
        return false
      }
    }

    if (this.$route.query.token !== undefined) {
      this.tockenLogin(this.$route.query.token)
      return false
    }

    this.isLogin() // 检测是否有会话 有的话直接进入主页面
  }
}
</script>
